package com.zwg.tingshu.search.client.receiver;


import com.zwg.tingshu.common.constant.RocketMqConstant;
import com.zwg.tingshu.search.client.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = RocketMqConstant.QUEUE_ALBUM_LOWER,
        selectorExpression = "*",
        consumerGroup = "zwg",
        consumeMode = ConsumeMode.ORDERLY,  //顺序消费，并发度为1
        maxReconsumeTimes = 3
)
public class SearchLowerReceiver implements RocketMQListener<String> {

    @Autowired
    private SearchService searchService;

    /**
     * 监听专辑下架消息，完成索引库删除
     * 考虑：1.要不要进行幂等性处理 2.是否需要进行事务管理（不需要）
     *
     * @param message
     */
    @Override
    public void onMessage(String message) {
        log.info("[搜索服务]监听到专辑下架消息：{}", message);
        searchService.lowerAlbum(Long.valueOf(message));
    }
}